package ldkxingzhe.animation.chapter5;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import ldkxingzhe.animation.R;

/**
 * Created by ke on 15-11-3.
 */
public class OrreyActivity extends AppCompatActivity{
    private final String TAG = OrreyActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chapter5_activity_orrey);
        ImageView imageView = (ImageView)findViewById(R.id.chapter5_image_view);
        OrreryDrawable orreryDrawable = OrreryDrawable.create();
        imageView.setImageDrawable(orreryDrawable);

        PropertyValuesHolder earthValues = PropertyValuesHolder.ofFloat("EarthPosition", 0 , (float)(2 * Math.PI));
        PropertyValuesHolder moonValues = PropertyValuesHolder.ofFloat("MoonPosition", 0, (float)(2 * Math.PI * 13));

        ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(orreryDrawable,earthValues, moonValues);
        objectAnimator.setDuration(10000);
        objectAnimator.setRepeatMode(ValueAnimator.RESTART);
        objectAnimator.setRepeatCount(5);
        objectAnimator.setInterpolator(new LinearInterpolator());
        objectAnimator.start();
    }
}
